<!DOCTYPE html>
<html lang="en">
  <head>
    <title>LoggerAPI  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset="utf-8">
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
    <script src="js/lunr.min.js" defer></script>
    <script src="js/typeahead.jquery.js" defer></script>
    <script src="js/jazzy.search.js" defer></script>
  </head>
  <body>


    <a title="LoggerAPI  Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="index.html">
          LoggerAPI Docs
        </a>
         (100% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/IBM-Swift/LoggerAPI/">
            <img class="header-icon" src="img/gh.png"/>
            View on GitHub
          </a>
        </p>
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="index.html">LoggerAPI Reference</a>
      <img class="carat" src="img/carat.png" />
      LoggerAPI  Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/Log.html">Log</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/LoggerMessageType.html">LoggerMessageType</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/Logger.html">Logger</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content">
            
            <p align="center">
    <a href="http://kitura.io/">
        <img src="https://raw.githubusercontent.com/IBM-Swift/Kitura/master/Sources/Kitura/resources/kitura-bird.svg?sanitize=true" height="100" alt="Kitura">
    </a>
</p>

<p align="center">
    <a href="https://ibm-swift.github.io/LoggerAPI/index.html">
    <img src="https://img.shields.io/badge/apidoc-LoggerAPI-1FBCE4.svg?style=flat" alt="APIDoc">
    </a>
    <a href="https://travis-ci.org/IBM-Swift/LoggerAPI">
    <img src="https://travis-ci.org/IBM-Swift/LoggerAPI.svg?branch=master" alt="Build Status - Master">
    </a>
    <img src="https://img.shields.io/badge/os-macOS-green.svg?style=flat" alt="macOS">
    <img src="https://img.shields.io/badge/os-linux-green.svg?style=flat" alt="Linux">
    <img src="https://img.shields.io/badge/license-Apache2-blue.svg?style=flat" alt="Apache 2">
    <a href="http://swift-at-ibm-slack.mybluemix.net/">
    <img src="http://swift-at-ibm-slack.mybluemix.net/badge.svg" alt="Slack Status">
    </a>
</p>
<h1 id='loggerapi' class='heading'>LoggerAPI</h1>

<p>A logger protocol that provides a common logging interface for different kinds of loggers. In addition, a class with a set of static functions for logging within your code is provided.</p>

<p><a href="https://github.com/IBM-Swift/Kitura">Kitura</a> uses this API throughout its implementation when logging.</p>
<h2 id='usage' class='heading'>Usage</h2>
<h4 id='add-dependencies' class='heading'>Add dependencies</h4>

<p>Add the <code>LoggerAPI</code> package to the dependencies within your application’s <code>Package.swift</code> file. Substitute <code>&quot;x.x.x&quot;</code> with the latest <code>LoggerAPI</code> <a href="https://github.com/IBM-Swift/LoggerAPI/releases">release</a>:</p>
<pre class="highlight swift"><code><span class="o">.</span><span class="nf">package</span><span class="p">(</span><span class="nv">url</span><span class="p">:</span> <span class="s">"https://github.com/IBM-Swift/LoggerAPI.git"</span><span class="p">,</span> <span class="nv">from</span><span class="p">:</span> <span class="s">"x.x.x"</span><span class="p">)</span>
</code></pre>

<p>Add <code>LoggerAPI</code> to your target&rsquo;s dependencies:</p>
<pre class="highlight swift"><code><span class="o">.</span><span class="nf">target</span><span class="p">(</span><span class="nv">name</span><span class="p">:</span> <span class="s">"example"</span><span class="p">,</span> <span class="nv">dependencies</span><span class="p">:</span> <span class="p">[</span><span class="s">"LoggerAPI"</span><span class="p">]),</span>
</code></pre>
<h4 id='import-package' class='heading'>Import package</h4>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">LoggerAPI</span>
</code></pre>
<h4 id='log-messages' class='heading'>Log messages</h4>

<p>Add log messages to your application:</p>
<pre class="highlight swift"><code><span class="kt">Log</span><span class="o">.</span><span class="nf">warning</span><span class="p">(</span><span class="s">"This is a warning."</span><span class="p">)</span>
<span class="kt">Log</span><span class="o">.</span><span class="nf">error</span><span class="p">(</span><span class="s">"This is an error."</span><span class="p">)</span>
</code></pre>
<h4 id='define-a-logger' class='heading'>Define a logger</h4>

<p>You need to define a <code>logger</code> in order to output these messages. You may wish to write your own <code><a href="Protocols/Logger.html">Logger</a></code> implementation, or you can use <code>HeliumLogger</code> that writes to standard output:</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">LoggerAPI</span>
<span class="kd">import</span> <span class="kt">HeliumLogger</span>

<span class="k">let</span> <span class="nv">myLogger</span> <span class="o">=</span> <span class="kt">HeliumLogger</span><span class="p">(</span><span class="o">.</span><span class="n">info</span><span class="p">)</span>
<span class="kt">Log</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">myLogger</span>
</code></pre>

<p>You can find out more about HeliumLogger <a href="https://github.com/IBM-Swift/HeliumLogger/blob/master/README.md">here</a>.</p>
<h4 id='logging-messages-to-swift-log' class='heading'>Logging messages to swift-log</h4>

<p>You can direct your log messages to be logged via <a href="https://github.com/apple/swift-log">swift-log</a> by setting the <code>swiftLogger</code> property:</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">LoggerAPI</span>
<span class="kd">import</span> <span class="kt">Logging</span>

<span class="k">let</span> <span class="nv">myLogger</span> <span class="o">=</span> <span class="kt">Logging</span><span class="o">.</span><span class="kt">Logger</span><span class="p">(</span><span class="nv">label</span><span class="p">:</span> <span class="s">"myLogger"</span><span class="p">)</span>
<span class="n">myLogger</span><span class="o">.</span><span class="n">logLevel</span> <span class="o">=</span> <span class="o">.</span><span class="n">notice</span>
<span class="kt">Log</span><span class="o">.</span><span class="n">swiftLogger</span> <span class="o">=</span> <span class="n">myLogger</span>
</code></pre>

<p>If both <code>logger</code> and <code>swiftLogger</code> are set, then log messages will be sent to both logging backends. The log level configured for a LoggerAPI Logger and a swift-log Logger are independent, so may be used to log at different levels.</p>

<p>Note that because the hierarchy of log levels defined by LoggerAPI and swift-log is slightly different, a mapping is defined between the levels. See the documentation for <code>Log.isLogging()</code> for details.</p>
<h2 id='api-documentation' class='heading'>API documentation</h2>

<p>For more information visit our <a href="http://ibm-swift.github.io/LoggerAPI/">API reference</a>.</p>
<h2 id='community' class='heading'>Community</h2>

<p>We love to talk server-side Swift, and Kitura. Join our <a href="http://swift-at-ibm-slack.mybluemix.net/">Slack</a> to meet the team!</p>
<h2 id='license' class='heading'>License</h2>

<p>This library is licensed under Apache 2.0. Full license text is available in <a href="https://github.com/IBM-Swift/LoggerAPI/blob/master/LICENSE.txt">LICENSE</a>.</p>

          </div>
        </section>


      </article>
    </div>
    <section class="footer">
      <p>&copy; 2019 <a class="link" href="https://github.com/IBM-Swift/LoggerAPI" target="_blank" rel="external">IBM</a>. All rights reserved. (Last updated: 2019-06-10)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
